 //真机可以,模拟器不行
 let str = "", zss, zxs, swsl, swxl, zwss, zwxs, xwsl, xwxl
 importClass(android.net.TrafficStats)
  zss = ozs();
    zxs = ozx();

    swsl = 0;
    swxl = 0;
    zwss = 0;
    zwxs = 0;
    thread.execAsync(function () {
        swsl = ozs();
        swxl = ozx();
        while (true) {
            sleep(1000);
            xwsl = ozs();
            xwxl = ozx();
            zwss = xwsl - swsl;
            zwxs = xwxl - swxl;
            swsl = xwsl;
            swxl = xwxl;
        }

    });
    // logd(TrafficStats.getTotalRxBytes());
    while (true) {
        let str = "\n流量↑:" + sz(lzs()) +
            "\n流量↓:" + sz(lzx()) +
            "\n网速↑:" + sz(zwss) + "\/s" +
            "\n网速↓:" + sz(zwxs) + "\/s";

        logd(str);
        sleep(1000);

    }


function ozs() {
    return TrafficStats.getTotalTxBytes();
}

function ozx() {
    return TrafficStats.getTotalRxBytes();
}

function lzs() {
    return ozs() - zss;
}

function lzx() {
    return ozx() - zxs;
}

function sz(num) {
    if (num < 1024) {
        return num.toFixed(2) + "by";
    } else {
        num /= 1024
    }
    if (num < 1024) {
        return num.toFixed(2) + "Kb";
    } else {
        num /= 1024
    }
    if (num < 1024) {
        return num.toFixed(2) + "Mb";
    } else {
        num /= 1024
    }
    if (num < 1024) {
        return num.toFixed(2) + "Gb";
    } else {
        num /= 1024
    }
    if (num < 1024) {
        return num.toFixed(2) + "Tb";
    } else {
        num /= 1024
    }
    if (num < 1024) {
        return num.toFixed(2) + "Pb";
    } else {
        num /= 1024
    }
    return num.toFixed(2) + "Eb";
}
